home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / May / di9805bt / copy / COPYF.PAS < prev   
Pascal/Delphi Source File  |  1997-12-29  |  2KB  |  71 lines

  1. unit Copyf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, FileCtrl, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     FileListBox1: TFileListBox;
  12.     DirectoryListBox1: TDirectoryListBox;
  13.     DriveComboBox1: TDriveComboBox;
  14.     FilterComboBox1: TFilterComboBox;
  15.     CopyBtn: TButton;
  16.     DestEdit: TEdit;
  17.     GroupBox1: TGroupBox;
  18.     GroupBox2: TGroupBox;
  19.     Label1: TLabel;
  20.     procedure CopyBtnClick(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure CopyFile(srcName, DestName: String);
  35. {
  36. Copies the source file to the destination
  37. file.
  38. }
  39. var
  40.   buff:        array[1..8192] of Char;
  41.   srcFile,
  42.   destFile:    File;
  43.   readCount,
  44.   writeCount:  Integer;
  45. begin
  46.   {Open the source file.}
  47.   Assign(srcFile, srcName);
  48.   Reset(srcFile, 1);
  49.   {Open the destination file.}
  50.   Assign(destFile, destName);
  51.   Rewrite(destFile, 1);
  52.   {Copy a buffer full at a time until the
  53.    end of the file is reached or a write
  54.    error occurs.}
  55.   repeat
  56.     BlockRead(srcFile, buff, SizeOf(buff), readCount);
  57.     BlockWrite(destFile, buff, readCount, writeCount);
  58.   until (readCount = 0) or (writeCount < readCount);
  59.   {Close the files.}
  60.   System.Close(srcFile);
  61.   System.Close(destFile);
  62. end;
  63.  
  64. procedure TForm1.CopyBtnClick(Sender: TObject);
  65. begin
  66.   CopyFile(FileListBox1.Filename, DestEdit.Text);
  67. end;
  68.  
  69.  
  70. end.
  71.